package com.zglc.ms.shop.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.zglc.ms.shop.model.ProductPrice;

@Repository
public class ProductPriceDao {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public List<ProductPrice> list(int productId) {
		final String sql = "SELECT price_type, price_value FROM shop_product_price WHERE product_id = ? ORDER BY price_type";
		try {
			List<ProductPrice> list = jdbcTemplate.query(sql, new Object[] { productId }, (rs, rowNum) -> {
				ProductPrice productPrice = new ProductPrice();
				productPrice.setPriceType(rs.getInt("price_type"));
				productPrice.setPriceValue(rs.getInt("price_value"));
				return productPrice;
			});

			return list;
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			logger.error("ProductPrice List error: productId---"+ productId);
			return null;
		}
	}

}